
define(function (require, exports) {
	/**
	 * 页面加载完成时触发
	 * @param hashCode 路由ID
	 * @param data 传递数据对象
	 * @param cite 页面站点信息
	 */
	exports.ready = function (hashCode, data, cite) {
		yufp.lookup.reg('USE_TASK_STATE,USE_ALERTM_MODE');
		yufp.custom.vue({
			el: cite.el,
			data: function () {
				/*定义校验规则，只能填字母数字 下划线*/
				var valiCodes = function (rule, value, callback) {
					var reg = /^[0-9a-zA-Z_]{1,}$/;
					if (value && reg.test(value)) {
						if (value.length > 64) {
							callback(new Error('长度不能大于64位'));
						} else {
							callback();
						}
					} else if (value && !reg.test(value)) {
						callback(new Error('能填字母、数字和下划线'));
					} else {
						callback();
					}
				};
				/**检验数字为0-255*/
				var numMax = function (rule, value, callback) {
					if (value) {
						if (Number(value) >= 0 && Number(value) <= 255) {
							callback();
						} else {
							callback(new Error('返回值必须为0-255之间'));
						}
					} else {
						callback();
					}
				};
				var _this = this;
				return {
					tbHeight:'0',
					disfalse: true,//是否可以编辑对象信息
					searchFormdata: {},
					appOption: [],
					groupOption: [],
					actionOption: [],
					addFnButton: !yufp.session.checkCtrl('addFn'),
					updateFnButton: !yufp.session.checkCtrl('updateFn'),
					deleteFnButton: !yufp.session.checkCtrl('deleteFn'),
					importFnButton: !yufp.session.checkCtrl('importFn'),
					exportFnButton: !yufp.session.checkCtrl('exportFn'),
					upLoadDialogVisible: false,
					excelloading: false,
					upLoadUrl: yufp.service.getUrl({
						url: "api/file/provider/uploadfile"
					}),
					multipleFalg: false,
					appUploadDatas: [],
					errdata: [
					],
					errshow: false,

					treeDataUrl: "api/use/plats/paramValue/queryWarningJobTreeList",
					dataUrl: 'api/use/warnings/job/queryList',
					objDataUrl: "api/use/warnings/job/queryUseAlarmTargetList",
					groupDataUrl: "api/use/warnings/groups/queryList",//对象组列表查询
					objDataUserUrl: "api/adminsmuser/querypage",
					cancelBtnShow: true,
					addBtnShow: false,
					formdata: {},
					async: false,
					height: yufp.frame.size().height - 92,
					dialogVisible: false,
					formDisabled: false,
					classCodeDisabled: false,
					viewTitleArrry: ['作业警示条件新增', '作业警示条件修改', '作业警示条件查看'],
					viewTitle: '',
					activeTabName: 'basicInfo',
					collActiveNames: "collBasic",
					propTabaleData: [],
					appCodeShow: true,
					appShowName: "aaa",
					nodeData: '', // 在新增表格数据时需要先获取当前树节点，再把一条新的记录加到这个节点下的表格里,
					nodeLeaf: false,
					isDisabledAppName: false,
					isReadOnly: false,
					queryName: "",
					alarmClassOptions: [],
					currentCheckObjt: {},
					exceptDatas: [],
					exceptTimeDialogVisible: false,
					objectTabVisible: false,
					groupTabVisible: false,//对象组dialog展示标志
					objectUserTabVisible: false,
					condData: [],
					condDataModel: {},
					classCode: "",
					eventAppOptions: [],
					eventCodeOptions: [],
					objDatas: [],
					isView: [],
					templateDatas: [],
					currTemplateDatas: [],
					templateDatasClass: [[], [], [], []], //0,代表手机短信，1代表电子邮件 2. 代表控制台 3,全部（对象组）
					baseParam: { condition: { orgId: yufp.session.org.id } },
					integerRules: [{ required: true, message: '必填项' },
					{ message: '请输入数字', validator: yufp.validator.number },
					{ validator: numMax, trigger: 'blur' }
					],
					integerRules2: [{ required: true, message: '必填项' },
					{ message: '请输入数字', validator: yufp.validator.number }
					],
					datatimeOptions: [{ key: "R", value: "相对日期" }, { key: "F", value: "固定日期" }, { key: "C", value: "日历类型" }],

					queryObjUserFields: [{ placeholder: '登录代码/姓名/员工号', field: 'userInfo', type: 'input' }],

					queryObjUserButtons: [
						{
							label: '搜索', op: 'submit', type: 'primary', click: function (model, valid) {

								model.orgId = yufp.session.org.id;


								_this.$refs.refObjUserTable.remoteData({ condition: model });
							}
						},
						{
							label: '确认', op: 'submit', type: 'primary', click: function () {
								let selectDatas = _this.$refs.refObjUserTable.selections;
								for (var i = 0; i < selectDatas.length; i++) {

									var obj = {};
									obj.alarmMode = 'N';
									obj.targetName = selectDatas[i].userName;
									obj.targetData = selectDatas[i].loginCode;
									_this.objDatas.push(obj);


								}
								_this.$refs.refObjUserTable.selections.splice(0);
								_this.objectUserTabVisible = false;
							}
						}
					],


					queryObjFields: [{ placeholder: '报警方式', field: 'alarmMode', type: 'select', dataCode: "USE_ALERTM_MODE" },
					{ placeholder: '对象名称', field: 'targetName', type: 'input' }],
					alarmModeDatas: [
						{ key: 'S', value: '手机短信' },
						{ key: 'M', value: '电子邮件' },
						{ key: 'N', value: '控制台通知' },
						{ key: '+', value: '对象组' }
					],
					//警示对象组查询条件
					queryGroupFields: [
						{ placeholder: '警示对象组编号', field: 'groupCode', type: 'input' },
						{ placeholder: '警示对象组名称', field: 'groupName', type: 'input' }
					],
					//警示对象组处理按钮
					queryGroupButtons: [
						{
							label: '搜索', op: 'submit', type: 'primary', click: function (model, valid) {
								_this.$refs.refGroupUsedTable.remoteData({ condition: model });
							}
						},
						{
							label: '确认', op: 'submit', type: 'primary', click: function () {
								var selectDatas = _this.$refs.refGroupUsedTable.selections;
								for (var i = 0; i < selectDatas.length; i++) {
									var isContain = false;
									for (var j = 0; j < _this.objDatas.length; j++) {
										if (selectDatas[i].targetCode === _this.objDatas[j].targetCode
											&& selectDatas[i].alarmMode === _this.objDatas[j].alarmMode) {
											isContain = true;
											break;
										}
									}
									if (!isContain) {
										var obj = {};
										obj.alarmMode = selectDatas[i].alarmMode;
										obj.targetName = selectDatas[i].groupName;
										obj.targetCode = selectDatas[i].groupCode;
										_this.objDatas.push(obj);
									}
								}
								_this.$refs.refGroupUsedTable.selections.splice(0);
								_this.groupTabVisible = false;
							}
						}
					],
					queryObjButtons: [
						{
							label: '搜索', op: 'submit', type: 'primary', click: function (model, valid) {

								console.log(model);
								_this.$refs.refObjUsedTable.remoteData({ condition: model });
							}
						},
						{
							label: '确认', op: 'submit', type: 'primary', click: function () {
								let selectDatas = _this.$refs.refObjUsedTable.selections;
								for (var i = 0; i < selectDatas.length; i++) {
									var isContain = false;
									for (var j = 0; j < _this.objDatas.length; j++) {
										if (selectDatas[i].targetCode === _this.objDatas[j].targetCode
											&& selectDatas[i].alarmMode === _this.objDatas[j].alarmMode) {
											isContain = true;
											break;
										}
									}
									if (!isContain) {
										var obj = {};
										obj.alarmMode = selectDatas[i].alarmMode;
										obj.targetName = selectDatas[i].targetName;
										obj.targetData = selectDatas[i].targetData;
										obj.targetCode = selectDatas[i].targetCode;
										_this.objDatas.push(obj);
									}
								}
								_this.$refs.refObjUsedTable.selections.splice(0);
								_this.objectTabVisible = false;
							}
						}
					],
					basicInfoFormFields: [
						{
							columnCount: 2,
							fields: [
								{
									field: 'appCode',
									label: '应用系统:',
									type: "select",
									options: [],
									filterable:true,
									change: _this.formChangeAppCode,
									rules: [{ required: true, message: '必填项', trigger: 'blur' }]
								},
								{
									field: 'groupCode',
									label: '所属流程:',
									type: "select",
									filterable: true,
									options: [],
									change: _this.formChangegroupCode,
									rules: [{ required: true, message: '必填项', trigger: 'blur' }]
								},

								{
									field: 'actionCode',
									label: '所属作业:',
									filterable:true,
									type: "select",
									options: [],
									rules: [{ required: true, message: '必填项', trigger: 'blur' }]
								}

							],
						}],

					warnsInfoFormFields: [{
						columnCount: 2,
						fields: [{
							field: 'ruleCode',
							label: '条件代码:',
							rules: [{ max: 64, message: '输入值过长', trigger: 'blur' },
							{ validator: valiCodes, trigger: 'blur' }
							]
						}, {
							field: 'ruleName',
							label: '条件名称:',
							rules: [{ required: true, message: '必填项', trigger: 'blur' },
							{ max: 120, message: '输入值过长', trigger: 'blur' }]
						},
						{
							field: 'validFlag',
							label: '条件状态:',
							type: "select",
							filterable:true,
							dataCode: "USE_TASK_STATE",
							rules: [{ required: true, message: '必填项', trigger: 'blur' }]
						}

						],
					}],

					condInfoFormFields: [{
						columnCount: 2,
						fields: []
					}],

					remarkFields: [{
						columnCount: 1,
						fields: [{
							field: 'remark',
							label: '备注:',
							type: "textarea",
							rows: 3
						}]
					}
					],

					firstStepFormButtons: [
						{
							label: '取消',
							hidden: false,
							click: function () {
								_this.cancelFn();

							}
						},
						{
							label: '下一步',
							type: 'primary',
							hidden: false,
							click: function () {
								_this.nextStepFn();
							}
						}

					],

					exceptTimeFields: [{
						columnCount: 1,
						fields: [
							{
								// 时点类型
								field: 'timeType',
								label: '时点类型:',
								type: "select",
								change: _this.changeTimeType,
								value: 'R',
								options: [{ key: "R", value: "相对日期" }, { key: "F", value: "固定日期" }],
								rules: [{ required: true, message: '必填项', trigger: 'blur' }]
							},
							{
								field: 'fixedTimeRange',
								label: '相对范围:',
								type: "select",
								filterable:true,
								dataCode: "USE_FIXED_TIME_RANGE",
								hidden: false,
								rules: [{ required: true, message: '必填项', trigger: 'blur' }]
							},

							{
								field: 'fixedTimef',
								label: '相对前后:',
								type: "select",
								filterable:true,
								dataCode: "USE_FIXED_TIME_F",
								hidden: false,
								rules: [{ required: true, message: '必填项', trigger: 'blur' }]
							},
							{
								field: 'fixedDays',
								label: '相对天数:',
								filterable:true,
								hidden: false,
								rules: [
									{ required: true, message: '必填项', trigger: 'blur' },
									{ message: '请输入数字', validator: yufp.validator.number }]
							},
							{
								field: 'fixedTime',
								label: '固定日期:',
								type: 'date',
								hidden: false,
								//valueformat: "MMdd",
								//readonly: true,
								format: 'MMdd',
								change: _this.changeDate,
								rules: [{ required: true, message: '必填项', trigger: 'blur' }],
							},
							{
								field: 'calenderType',
								label: '日历类型:',
								type: "select",
								filterable:true,
								options: [],
								rules: [{ required: true, message: '必填项', trigger: 'blur' }],
							}
						]
					}],

					exceptTimeFormButtons: [
						{
							label: '取消',
							hidden: false,
							click: function () {
								_this.cancelExceptimeFn();

							}
						},
						{
							label: '确认',
							type: 'primary',
							click: function () {
								_this.saveExceptTimeFn();
							}
						}
					],


					saveButtons: [

						{
							label: '保存', type: 'primary', hidden: false, op: 'submit', click: function (model, valid) {
								_this.saveFn();
							}
						},
						{
							label: '取消', hidden: false, click: function (model) {
								_this.cancelFn();
							}
						}
					]
				};
			},
			mounted: function () {
				var _this = this;
				//测试
				_this.$nextTick(function(){
						var tableBox = _this.$refs.tableBox;
						let a = tableBox.getBoundingClientRect().top + 28;
						var theight = `calc(100vh - ${a}px - 64px)`;
						_this.tbHeight = theight;		
				});
				_this.queryAppList();
				yufp.service.request({
					method: 'GET',
					url: "api/use/plats/paramValue/queryWarningJobTreeList",
					data: {},
					async: false,
					callback: function (code, message, response) {
						if (response.code != 0) {
							_this.$message(response.message);
						} else {
							_this.alarmClassOptions.splice(0);
							for (let i = 0; i < response.data.length; i++) {
								_this.alarmClassOptions.push({ key: response.data[i].paramCode, value: response.data[i].paramName });
							}
						}

					}
				});

			},
			methods: {

				//点击导出模板操作
				exportDemo: function () {
					var _this = this;
					var condition = { busiType: "JOBWARN" };
					var search = _this.searchFormdata;
					yufp.util.download("api/use/excel/exportTempExcel?condition="
						+ encodeURI(JSON.stringify(condition)));
				},

				//点击导出操作
				exportExcelFn: function () {
					var _this = this;
					var condition = { busiType: "JOBWARN" };
					var search = _this.searchFormdata;
					condition.appCode = search.appCode;
					condition.groupCode = search.groupCode;
					condition.actionCode = search.actionCode;

					if(this.currentCheckObjt.paramCode!='0000'&&this.currentCheckObjt.paramCode !=''){
						condition.alarmClass = this.currentCheckObjt.paramCode;
					}else{
						condition.alarmClass = "";
					}

					var selectDatas = _this.$refs.refTable.selections;

					if (selectDatas.length > 0) {
						condition.dataList = selectDatas;
					}

					_this.exportLoading = true;
					yufp.service.request({
						method: 'POST',
						url: '/api/use/excel/exportExcelForWeb',
						data: { condition: condition },
						callback: function (code, message, response) {
							_this.exportLoading = false;
							if (response.code === 0) {
								yufp.util.download("api/use/excel/downLoadExcel?filePath=" + response.data.allFilePath + "&fileName=" + response.data.fileName);
							} else {
								_this.$message.error('导出失败');
							}
						}
					});
				},

				importExcelFn: function () { //点击导入操作
					this.upLoadDialogVisible = true;
					this.$nextTick(function () {
						this.$refs['my-upload'].clearFiles();
						this.errshow = false;
						this.errdata = [];
					})
				},

				/**
				 *导入前的检验操作操作
				 */
				checkUpload: function (file) {
					//alert(file);

					var isLt10M = file.size / 1024 / 1024 < 100;
					if (!isLt10M) {
						this.$message.error('上传文件大小不能超过 100MB!');
					}
					var index = file.name.lastIndexOf('.');
					var ext = file.name.substr(index + 1);

					var suffixValid = ('xlsx' === ext || 'xls' === ext);
					if (!suffixValid) {
						this.$message.error('上传文件的格式必须为excel格式');
						return false;
					}
					return isLt10M && suffixValid;
				},

				successUpload: function (response, file, fileList) { //导入成功后执行
					/*	console.log('上传成功！')
                        this.$refs['my-upload'].clearFiles();*/


					const _this = this;
					const param = {};
					/* 					_this.$loading({
                                            target:'.load-target',
                                            body:true
                                        }) */
					_this.excelloading = true;
					param.busiType = "JOBWARN";
					param.excelUpLoadFile = response.data;
					yufp.service.request({
						method: 'POST',
						url: '/api/use/excel/importExcel',
						data: param,
						timeout: 1800000,
						callback: function (code, message, response) {
							_this.excelloading = false;
							if (response.code == 0 && response.data.errorInfos.length == 0 && response.data.impStatus !=
								'失败') {
								_this.$refs['my-upload'].clearFiles();
								_this.errshow = false;
								_this.errdata = [];
								_this.upLoadDialogVisible = false;
								_this.$message('导入成功!');
								//同时重新查询列表

								var param = {
									condition: JSON.stringify(_this.searchFormdata)
								};
								_this.$refs.refTable.remoteData(param);

							} else {
								_this.errshow = true;
								_this.$refs['my-upload'].clearFiles();
								_this.errdata = [];
								if (response.data && response.data.errorInfos.length > 0 && response.data.errorInfos[
									0].errorList) {
									response.data.errorInfos[0].errorList.map(function (item, index) {
										_this.errdata.push({
											"errMsg": item
										})
										console.log('errdata', _this.errdata)
									})
								} else {
									_this.errdata.push({
										"errMsg": response.message
									})
								}

							}
						}
					});
				},

				reloadData: function () {
					var _this = this;
					var paramCode = "";
					if (_this.currentCheckObjt.paramCode != null && _this.currentCheckObjt.paramCode != '') {
						paramCode = _this.currentCheckObjt.paramCode;
					}
					var paramObj = _this.searchFormdata;
					paramObj.alarmClass = paramCode;
					_this.$refs.refTable.remoteData({ condition: paramObj });
				},

				changeDate: function (val) {
					this.$refs.excetTimeForm.formModel.fixedTime = this.formartDate(val);
				},

				formChangeAppCode: function (val) {
					this.queryGroupCodeList(val, 'form');
				},

				changeApp: function (val) {
					this.queryGroupCodeList(val);
				},

				changeGroupCode: function (val) {
					this.queryActionCodeList(this.searchFormdata.appCode, val);
				},

				formChangegroupCode: function (val) {
					this.queryActionCodeList(this.$refs.refBasicForm.formModel.appCode, val, 'form');
				},


				addExceptCfg: function () {
					var _this = this;
					_this.exceptTimeDialogVisible = true;
					_this.loadCalendarTypeByApp(_this.$refs.refBasicForm.formModel.appCode);
					_this.$nextTick(function () {
						_this.$refs.excetTimeForm.resetFields();

					});
				},

				addObjCfg: function () {
					var obj = { alarmMode: "S", targetName: "", targetData: "", remark: "" };
					this.objDatas.push(obj);
				},
				deleteObjCfg: function () {
					var _this = this;
					let selectDatas = _this.$refs.refObjTab.selections;
					for (let jdx = _this.objDatas.length - 1; jdx >= 0; jdx--) {
						for (let idx = 0; selectDatas.length > idx; idx++) {
							if (_this.objDatas[jdx] == selectDatas[idx]) {
								_this.objDatas.splice(jdx, 1);
								break;
							}
						}

					}
				},


				changeTimeType: function (val) {
					var _this = this;
					if (val === 'R') {
						_this.$set(_this.exceptTimeFields[0].fields[1].rules[0], "required", true);
						_this.$set(_this.exceptTimeFields[0].fields[2].rules[0], "required", true);
						_this.$set(_this.exceptTimeFields[0].fields[3].rules[0], "required", true);
						_this.$set(_this.exceptTimeFields[0].fields[4].rules[0], "required", false);
						_this.$set(_this.exceptTimeFields[0].fields[5].rules[0], "required", false);
						_this.$set(_this.exceptTimeFields[0].fields[1], 'hidden', false);
						_this.$set(_this.exceptTimeFields[0].fields[2], 'hidden', false);
						_this.$set(_this.exceptTimeFields[0].fields[3], 'hidden', false);
						_this.$set(_this.exceptTimeFields[0].fields[4], 'hidden', true);
						_this.$set(_this.exceptTimeFields[0].fields[5], 'hidden', true);
					} else if (val === 'F') {
						_this.$set(_this.exceptTimeFields[0].fields[1].rules[0], "required", false);
						_this.$set(_this.exceptTimeFields[0].fields[2].rules[0], "required", false);
						_this.$set(_this.exceptTimeFields[0].fields[3].rules[0], "required", false);
						_this.$set(_this.exceptTimeFields[0].fields[4].rules[0], "required", true);
						_this.$set(_this.exceptTimeFields[0].fields[5].rules[0], "required", false);
						_this.$set(_this.exceptTimeFields[0].fields[1], 'hidden', true);
						_this.$set(_this.exceptTimeFields[0].fields[2], 'hidden', true);
						_this.$set(_this.exceptTimeFields[0].fields[4], 'hidden', false);
						_this.$set(_this.exceptTimeFields[0].fields[3], 'hidden', true);
						_this.$set(_this.exceptTimeFields[0].fields[5], 'hidden', true);
					} else if (val === 'C') {
						_this.$set(_this.exceptTimeFields[0].fields[1].rules[0], "required", false);
						_this.$set(_this.exceptTimeFields[0].fields[2].rules[0], "required", false);
						_this.$set(_this.exceptTimeFields[0].fields[3].rules[0], "required", false);
						_this.$set(_this.exceptTimeFields[0].fields[4].rules[0], "required", false);
						_this.$set(_this.exceptTimeFields[0].fields[5].rules[0], "required", true);
						_this.$set(_this.exceptTimeFields[0].fields[1], 'hidden', true);
						_this.$set(_this.exceptTimeFields[0].fields[2], 'hidden', true);
						_this.$set(_this.exceptTimeFields[0].fields[3], 'hidden', true);
						_this.$set(_this.exceptTimeFields[0].fields[4], 'hidden', true);
						_this.$set(_this.exceptTimeFields[0].fields[5], 'hidden', false);
					}

				},

				deleteExceptCfg: function () {
					var _this = this;
					let selectDatas = _this.$refs.refExceptTab.selections;
					for (let jdx = _this.exceptDatas.length - 1; jdx >= 0; jdx--) {
						for (let idx = 0; selectDatas.length > idx; idx++) {
							if (_this.exceptDatas[jdx] == selectDatas[idx]) {
								_this.exceptDatas.splice(jdx, 1);
								break;
							}
						}

					}

				},

				cancelExceptimeFn: function () {
					this.exceptTimeDialogVisible = false;
				},
				saveExceptTimeFn: function () {
					var _this = this;
					var validate = false;

					console.log(_this.$refs.excetTimeForm.formModel);
					_this.$refs.excetTimeForm.validate(function (valid) {
						validate = valid;
					});
					if (!validate) {
						return;
					}

					var obj = {};
					let exceptTimeVal = "";
					let exceptTimeDesc = "";
					if (_this.$refs.excetTimeForm.formModel.timeType === 'R') {

						if (_this.$refs.excetTimeForm.formModel.fixedDays >= 100) {
							_this.$message({ message: "相对天数最大值不能大于或等于100", type: "warning" });
							return
						}

						exceptTimeVal = _this.$refs.excetTimeForm.formModel.fixedTimeRange + _this.$refs.excetTimeForm.formModel.fixedTimef;

						if (_this.$refs.excetTimeForm.formModel.fixedDays < 10) {
							exceptTimeVal += "0" + _this.$refs.excetTimeForm.formModel.fixedDays;
						} else {
							exceptTimeVal += "" + _this.$refs.excetTimeForm.formModel.fixedDays;
						}


						exceptTimeDesc = _this.getFixedTimeRange(_this.$refs.excetTimeForm.formModel.fixedTimeRange)
							+ _this.getFixedTimef(_this.$refs.excetTimeForm.formModel.fixedTimef)
							+ _this.$refs.excetTimeForm.formModel.fixedDays + "天";


					} else if (_this.$refs.excetTimeForm.formModel.timeType === 'F') {

						exceptTimeVal = _this.$refs.excetTimeForm.formModel.fixedTime.substr(0, 2) +
							"" + _this.$refs.excetTimeForm.formModel.fixedTime.substr(3, 2);

						exceptTimeDesc = _this.$refs.excetTimeForm.formModel.fixedTime.substr(0, 2) + "月"
							+ _this.$refs.excetTimeForm.formModel.fixedTime.substr(3, 2) + "日";
					} else if (_this.$refs.excetTimeForm.formModel.timeType === 'C') {
						exceptTimeVal = "@DT" + _this.$refs.excetTimeForm.formModel.calenderType;
						exceptTimeDesc = _this.getCalendarTypeInfo(_this.$refs.excetTimeForm.formModel.calenderType);
					}

					obj.exceptTime = exceptTimeVal;
					obj.timeType = _this.$refs.excetTimeForm.formModel.timeType;
					obj.exceptTimeDesc = exceptTimeDesc;
					_this.exceptDatas.push(obj);
					_this.exceptTimeDialogVisible = false;

				},

				getFixedTimeRange: function (val) {
					if ("Y" === val) {
						return "年";
					} else if ("H" === val) {
						return "半年";
					} else if ("Q" === val) {
						return "季";
					} else if ("M" === val) {
						return "月"
					} else if ("T" === val) {
						return '旬';
					} else {
						return "周";
					}

				},

				getCalendarTypeInfo: function (val) {
					var _this = this;
					for (let i = 0; i < _this.exceptTimeFields[0].fields[5].options.length; i++) {
						if (_this.exceptTimeFields[0].fields[5].options[i].key === val) {
							return _this.exceptTimeFields[0].fields[5].options[i].value;
						}
					}

					return "";
				},

				getFixedTimef: function (val) {
					if (val === '-') {
						return "末前";
					} else {
						return "初后";
					}

				},



				formartDate: function (val) {
					var d = new Date(val);
					var year = d.getFullYear();
					var month = (d.getMonth() + 1) < 10 ? '0' + (d.getMonth() + 1) : (d.getMonth() + 1);
					var date = d.getDate() < 10 ? '0' + d.getDate() : d.getDate();
					var hour = d.getHours() < 10 ? '0' + d.getHours() : d.getHours();
					var minutes = d.getMinutes() < 10 ? '0' + d.getMinutes() : d.getMinutes();
					var seconds = d.getSeconds() < 10 ? '0' + d.getSeconds() : d.getSeconds();
					//return year +"-"+ month+ "-"+date;
					return month + "-" + date;
				},


				/**
				 * 取消
				 */
				cancelFn: function () {
					var _this = this;
					_this.dialogVisible = false;

				},

				nextStepFn: function () {

					var _this = this;
					var validate = false;
					_this.$refs.refBasicForm.validate(function (valid) {
						validate = valid;
					});



					if (!validate) {
						_this.collActiveNames = "collBasic";
						return;
					}



					if (!_this.addFlag) {
						var isContainFlow = false;
						for (var i = 0; i < _this.basicInfoFormFields[0].fields[1].options.length; i++) {
							if (_this.basicInfoFormFields[0].fields[1].options[i].key === _this.$refs.refBasicForm.formModel.groupCode) {
								isContainFlow = true;
								break;
							}
						}
						if (!isContainFlow) {
							_this.$message({ message: "所属流程值不合法，请检查", type: "warning" });
							return
						}

						var isContainActionCode = false;
						for (var i = 0; i < _this.basicInfoFormFields[0].fields[2].options.length; i++) {
							if (_this.basicInfoFormFields[0].fields[2].options[i].key === _this.$refs.refBasicForm.formModel.actionCode) {
								isContainActionCode = true;
								break;
							}
						}
						if (!isContainActionCode) {
							_this.$message({ message: "所属作业值不合法，请检查", type: "warning" });
							return
						}


					}

					_this.$refs.refWarnsForm.validate(function (valid) {
						validate = valid;
					});

					if (!validate) {
						_this.collActiveNames = "collWarns";
						return;
					}

					_this.$refs.refCondForm.validate(function (valid) {
						validate = valid;
					});


					if (!validate) {
						_this.collActiveNames = "collCond";
						return;
					} else {

						if (_this.classCode === 'T') {
							if (parseFloat(_this.condDataModel.minValueT) > parseFloat(_this.condDataModel.maxValueT)) {
								_this.collActiveNames = "collCond";
								_this.$message({ message: "低于平均时间不能大于高于平均时间", type: "warning" });
								return;
							}
						} else if (_this.classCode === 'L') {

							if (parseFloat(_this.condDataModel.minValueL) > parseFloat(_this.condDataModel.maxValueL)) {
								_this.collActiveNames = "collCond";
								_this.$message({ message: "低于绝对时间不能大于高于绝对时间", type: "warning" });
								return;
							}
						} else if (_this.classCode === 'R') {
							if (parseFloat(_this.condDataModel.minValue) > parseFloat(_this.condDataModel.maxValue)) {
								_this.collActiveNames = "collCond";
								_this.$message({ message: "返回值下限不能大于返回值上线", type: "warning" });
								return;
							}

						}

						_this.activeTabName = "configInfo";
					}

				},
				lastStepFn: function () {
					this.activeTabName = "basicInfo";
				},

				/**
				 * 保存
				 */
				saveFn: function () {

					var _this = this;

					var paramObj = _this.$refs.refBasicForm.formModel;

					let isvalid = true;

					if (_this.objDatas.length == 0) {
						_this.$message({ message: "对象配置不能为空", type: "warning" });
						return;
					}

					for (var i = 0; i < _this.objDatas.length; i++) {
						if (_this.objDatas[i].alarmMode === '+') {
							if (_this.objDatas[i].targetName === '' || _this.objDatas[i].templateCode === '' ||
								_this.objDatas[i].targetName === undefined || _this.objDatas[i].templateCode === undefined) {
								isvalid = false;
								break;
							}
						} else {
							if (_this.objDatas[i].targetName === '' || _this.objDatas[i].targetData === '' || _this.objDatas[i].templateCode === '' ||
								_this.objDatas[i].targetName === undefined || _this.objDatas[i].targetData === undefined || _this.objDatas[i].templateCode === undefined) {
								isvalid = false;
								break;
							}
						}
					}
					if (!isvalid) {
						_this.$message({ message: "对象名称、对象地址、警示模板不能为空，请检查", type: "warning" });
						return;
					}

					/*warning templplate*/
					paramObj.ruleName = _this.$refs.refWarnsForm.formModel.ruleName;
					paramObj.validFlag = _this.$refs.refWarnsForm.formModel.validFlag;
					paramObj.ruleCode = _this.$refs.refWarnsForm.formModel.ruleCode;

					/*warnings*/
					paramObj.eventApp = _this.condDataModel.eventApp;
					paramObj.eventCode = _this.condDataModel.eventCode;
					paramObj.timeLimit = _this.condDataModel.timeLimit;
					if (_this.classCode === 'T') {
						paramObj.minValue = _this.condDataModel.minValueT;
						paramObj.maxValue = _this.condDataModel.maxValueT;
					} else if (_this.classCode === 'L') {
						paramObj.minValue = _this.condDataModel.minValueL;
						paramObj.maxValue = _this.condDataModel.maxValueL;
					} else if (_this.classCode === 'R') {
						paramObj.minValue = _this.condDataModel.minValue;
						paramObj.maxValue = _this.condDataModel.maxValue
					}

					paramObj.dateTypeObjList = _this.exceptDatas;
					paramObj.useAlarmRuleList = _this.objDatas;

					let urlparam = "";
					if (_this.addFlag) {
						paramObj.alarmClass = _this.currentCheckObjt.paramCode
						urlparam = 'api/use/warnings/job/saveWarningsJob';
					} else {
						urlparam = 'api/use/warnings/job/updateWarningsJob';
					}

					//回去备注信息
					var obj = _this.$refs.endRefForm.$refs.remark[0].value;
					paramObj.remark = obj || '';
					yufp.service.request({
						method: 'POST',
						url: urlparam,
						data: paramObj,
						callback: function (code, message, response) {

							if (response.code == 0) {
								_this.reloadData();
								_this.$message('操作成功');
								_this.dialogVisible = false;
							} else {
								_this.$message(response.message);
							}
						}
					});
				},

				changeConfigMethod: function (val) {
					const _this = this;
					_this.$set(_this.databaseServerAllField[0].fields[6], 'hidden', val === '0');
					_this.$set(_this.databaseServerAllField[0].fields[7], 'hidden', val === '0');
					_this.$set(_this.databaseServerAllField[0].fields[8], 'hidden', val === '0');
					_this.$set(_this.databaseServerAllField[1].fields[0], 'hidden', val === '1');

					_this.$set(_this.databaseServerAllField[0].fields[6].rules[0], 'required', val === '1');
					_this.$set(_this.databaseServerAllField[0].fields[7].rules[0], 'required', val === '1');
					_this.$set(_this.databaseServerAllField[0].fields[8].rules[0], 'required', val === '1');
					_this.$set(_this.databaseServerAllField[1].fields[0].rules[0], 'required', val === '0');
				},

				/**
				 * 点击树的结点，加载对应的数据
				 */
				nodeClickFn: function (nodeData, node, self) {
					var _this = this;
					var nodeApp = "";
					if (nodeData.paramCode !== '0000') {
						_this.nodeLeaf = true;
						nodeApp = nodeData.paramCode;
						_this.currentCheckObjt.paramCode = nodeData.paramCode;

					} else {
						_this.currentCheckObjt.paramCode = "";
						_this.nodeLeaf = false;
					}
					_this.reloadData();

					// _this.$refs.refTable.remoteData({condition:{alarmClass: nodeApp}});

				},

				/**
				 * 新增
				 */
				addFn: function () {
					var _this = this;
					_this.isReadOnly = false;
					_this.dialogVisible = true;
					_this.viewTitle = _this.viewTitleArrry[0];
					_this.classCode = _this.currentCheckObjt.paramCode;
					_this.addFlag = true;
					// _this.activeTabName="basicInfo";
					_this.activeTabName = "basicInfo";
					_this.collActiveNames = "collWarns";
					_this.isView = false;
					// _this.$set(_this.warnsInfoFormFields[0].fields[0], 'readonly',  false );
					//_this.$set(_this.databaseServerAllField[0].fields[0], 'readonly',  _this.isReadOnly );

					_this.$nextTick(function () {

						_this.$refs.refWarnsForm.switch(_this.warnsInfoFormFields[0].fields[0].field, 'disabled', false);
						_this.$refs.refBasicForm.resetFields();
						_this.$refs.refWarnsForm.resetFields();
						_this.exceptDatas.splice(0);
						_this.objDatas.splice(0);
						_this.$refs.refCondForm.resetFields();
						_this.$refs.endRefForm.resetFields();
						_this.queryTemplateDatas(_this.currentCheckObjt.paramCode);
					});
				},

				viewDataFn: function (data) {
					var _this = this;
					_this.isReadOnly = true;
					_this.viewTitle = _this.viewTitleArrry[2];
					_this.dialogVisible = true;
					_this.addFlag = false;
					_this.classCode = data.alarmClass;
					_this.isView = true;
					_this.activeTabName = "basicInfo";
					_this.collActiveNames = "collBasic";
					// _this.$set(_this.warnsInfoFormFields[0].fields[0], 'readonly',  true );
					if (_this.exceptDatas != null)
						_this.exceptDatas.splice(0);
					if (_this.objDatas != null)
						_this.objDatas.splice(0);

					_this.$nextTick(function () {
						_this.$refs.refWarnsForm.switch(_this.warnsInfoFormFields[0].fields[0].field, 'disabled', true);
						_this.$refs.refBasicForm.resetFields();
						_this.$refs.refWarnsForm.resetFields();
						_this.$refs.refCondForm.resetFields();
						_this.$refs.endRefForm.resetFields();
						_this.queryTemplateDatas(data.alarmClass);
						_this.queryLoadDataObj(data);

					});

				},
				/**
				 * 修改
				 */
				modifyFn: function () {
					var _this = this;
					if (_this.$refs.refTable.selections.length != 1) {
						_this.$message({ message: '请先选择一条记录', type: 'warning', duration: 6000 });
						return;
					}
					_this.isReadOnly = true;
					_this.viewTitle = _this.viewTitleArrry[1];
					_this.dialogVisible = true;
					_this.addFlag = false;
					_this.isView = false;
					_this.classCode = _this.$refs.refTable.selections[0].alarmClass;
					_this.activeTabName = "basicInfo";
					_this.collActiveNames = "collWarns";
					if (_this.exceptDatas != null)
						_this.exceptDatas.splice(0);
					if (_this.objDatas != null)
						_this.objDatas.splice(0);
					//_this.$set(_this.warnsInfoFormFields[0].fields[0], 'readonly',  true );

					_this.$nextTick(function () {

						_this.$refs.refWarnsForm.switch(_this.warnsInfoFormFields[0].fields[0].field, 'disabled', true);
						_this.$refs.refBasicForm.resetFields();
						_this.$refs.refWarnsForm.resetFields();
						_this.$refs.refCondForm.resetFields();
						_this.$refs.endRefForm.resetFields();
						_this.queryTemplateDatas(_this.$refs.refTable.selections[0].alarmClass);
						_this.queryLoadDataObj(_this.$refs.refTable.selections[0]);

					});
				},
				/**
				 * 删除
				 */
				deleteFn: function () {
					var _this = this;
					var selections = _this.$refs.refTable.selections;
					if (selections.length < 1) {
						_this.$message({ message: '请先至少选择一条记录', type: 'warning', duration: 6000 });
						return;
					}
					var len = selections.length, arr = [];
					for (var i = 0; i < len; i++) {
						arr.push(selections[i].id);
					}
					_this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
						confirmButtonText: '确定',
						cancelButtonText: '取消',
						type: 'warning', duration: 6000,
						center: true,
						callback: function (action) {
							if (action === 'confirm') {
								yufp.service.request({
									method: 'DELETE',
									url: "api/use/warnings/job/deleteWarningsJob",
									data: selections[0],
									callback: function (code, message, response) {
										if (response.code != 0) {
											isOk = false;
											_this.$message(response.message);
										} else {
											_this.$message('操作成功');
											_this.reloadData();

										}

									}
								});
							}
						}
					});
				},
				queryAppList: function () {
					var _this = this;
					yufp.service.request({
						method: 'GET',
						url: "api/use/plats/apps/getTreeWftList",
						data: {},
						async: false,
						callback: function (code, message, response) {
							if (response.code != 0) {
								_this.$message(response.message);
							} else {
								_this.basicInfoFormFields[0].fields[0].options.splice(0);
								_this.basicInfoFormFields[0].fields[0].options.push({ key: " ", value: "通用" });
								_this.eventAppOptions.splice(0);
								for (let i = 0; i < response.data.length; i++) {
									if (response.data[i].appCode != '0000') {
										_this.appOption.push({ key: response.data[i].appCode, value: response.data[i].appName });
										_this.basicInfoFormFields[0].fields[0].options.push({ key: response.data[i].appCode, value: response.data[i].appName });
										_this.eventAppOptions.push({ key: response.data[i].appCode, value: response.data[i].appName });
									}


								}
							}

						}
					});
				},

				queryGroupCodeList: function (appCode, formType) {

					var _this = this;
					if (formType === 'form') {
						// _this.basicInfoFormFields[0].fields[1].options.splice(0);
						// _this.basicInfoFormFields[0].fields[2].options.splice(0);
						_this.groupOption = [];
						_this.actionOption = [];
					} else {
						_this.groupOption = [];
						_this.actionOption = [];
						_this.searchFormdata.groupCode = "";
						_this.searchFormdata.actionCode = "";
					}
					if (appCode == '') {
						return;
					}
					if (appCode == ' ') {
						if (formType === 'form') {
							_this.basicInfoFormFields[0].fields[1].options.push({ key: " ", value: "通用" });
							_this.basicInfoFormFields[0].fields[2].options.push({ key: " ", value: "通用" });
						} else {
							_this.groupOption.push({ key: " ", value: "通用" });
							_this.actionOption.push({ key: " ", value: "通用" });
						}
					} else {
						if (formType === 'form') {
							_this.basicInfoFormFields[0].fields[1].options.splice(0);
							_this.basicInfoFormFields[0].fields[1].options.push({ key: " ", value: "通用" });
						} else {
							_this.groupOption.push({ key: " ", value: "通用" });
						}

						var paramObj = { appCodeEq: appCode };
						yufp.service.request({
							method: 'GET',
							url: "api/use/plats/workflow/queryWftGrpList",
							data: paramObj,
							async: false,
							callback: function (code, message, response) {
								if (response.code != 0) {
									_this.$message(response.message);
								} else {
									for (let i = 0; i < response.data.length; i++) {
										if (formType === 'form') {
											_this.basicInfoFormFields[0].fields[1].options.push(
												{ key: response.data[i].groupCode, value: response.data[i].groupName });
										} else {
											_this.groupOption.push({ key: response.data[i].groupCode, value: response.data[i].groupName });
										}

									}
								}

							}
						});

					}
				},

				queryActionCodeList: function (appCode, groupCode, formType) {
					var _this = this;

					if (formType === 'form') {
						_this.basicInfoFormFields[0].fields[2].options.splice(0);
						// _this.$refs.refBasicForm.formModel.actionCode = "";
					} else {
						_this.actionOption = [];
						_this.searchFormdata.actionCode = "";
					}

					if (groupCode == '') {
						return;
					} else if (groupCode == ' ') {
						if (formType === 'form') {
							_this.basicInfoFormFields[0].fields[2].options.push({ key: " ", value: "通用" });
						} else {
							_this.actionOption.push({ key: " ", value: "通用" });
						}
					} else {
						if (formType === 'form') {
							_this.basicInfoFormFields[0].fields[2].options.push({ key: " ", value: "通用" });
						} else {
							_this.actionOption.push({ key: " ", value: "通用" });
						}

						var paramObj = { appCode: appCode, groupCode: groupCode };
						yufp.service.request({
							method: 'GET',
							url: "api/use/plats/workflow/queryWftLstList",
							data: paramObj,
							async: false,
							callback: function (code, message, response) {
								if (response.code != 0) {
									_this.$message(response.message);
								} else {
									for (let i = 0; i < response.data.length; i++) {
										if (formType === 'form') {
											_this.basicInfoFormFields[0].fields[2].options.push({ key: response.data[i].actionCode, value: response.data[i].actionName });
										} else {
											_this.actionOption.push({ key: response.data[i].actionCode, value: response.data[i].actionName });
										}

									}
								}

							}
						});
					}
				},

				loadCalendarTypeByApp: function (appCode) {
					// _this.calendarTypeDatas.splice(0);
					var _this = this;

					if (appCode == null || appCode === '' || appCode === ' ') {
						if (_this.exceptTimeFields[0].fields[0].options.length == 3) {
							_this.exceptTimeFields[0].fields[0].options.splice(2, 1);
						}
						return;
					} else {
						var paramObj = {};
						paramObj.appCode = appCode;
						yufp.service.request({
							method: 'GET',
							url: "api/use/plats/calendar/queryUseCalendarTypeList",
							data: paramObj,
							async: false,
							callback: function (code, message, response) {
								if (response.code != 0) {
									_this.$message(response.message);
								} else {
									_this.exceptTimeFields[0].fields[5].options.splice(0);

									if (response.data.length > 0 && _this.exceptTimeFields[0].fields[0].options.length == 2) {
										_this.exceptTimeFields[0].fields[0].options.splice(2, 0, { key: "C", value: "日历类型" });
									}

									for (let i = 0; i < response.data.length; i++) {
										if (response.data[i].typeCode != '0')
											_this.exceptTimeFields[0].fields[5].options.push({ key: response.data[i].typeCode, value: response.data[i].typeName });

									}



								}

							}
						});
					}

				},

				changeEventApp: function (appCode) {
					var _this = this;
					_this.condDataModel.eventCode = "";
					if (appCode == null || appCode === '') {
						_this.eventCodeOptions.splice(0);
					} else {
						_this.queryeventCodeOptions(appCode);
					}
				},

				queryeventCodeOptions: function (appCode) {
					var _this = this;
					yufp.service.request({
						method: 'GET',
						url: "api/use/plats/event/queryListByApp",
						data: { appCode: appCode },
						async: false,
						callback: function (code, message, response) {
							if (response.code != 0) {
								_this.$message(response.message);
							} else {

								_this.eventCodeOptions.splice(0);
								for (let i = 0; i < response.data.length; i++) {
									_this.eventCodeOptions.push({ key: response.data[i].eventCode, value: response.data[i].eventName });
								}
							}

						}
					});
				},

				/**
				 * 查询模版数据
				 */
				queryTemplateDatas: function (alarmClass) {
					var _this = this;
					var param = {};
					param.alarmClass = alarmClass;
					yufp.service.request({
						method: 'GET',
						url: "/api/use/warning/template/TemplateNoPage",
						data: { condition: JSON.stringify(param) },
						async: false,
						callback: function (code, message, response) {
							if (response.code != 0) {
								_this.$message(response.message);
							} else {
								_this.templateDatas.splice(0);
								_this.templateDatasClass[0].splice(0);
								_this.templateDatasClass[1].splice(0);
								_this.templateDatasClass[2].splice(0);
								_this.templateDatasClass[3].splice(0);
								for (let i = 0; i < response.data.length; i++) {
									_this.templateDatas.push({ key: response.data[i].templateCode, value: response.data[i].templateName });
									if (response.data[i].alarmMode === 'S') {
										_this.templateDatasClass[0].push({ key: response.data[i].templateCode, value: response.data[i].templateName });
									} else if (response.data[i].alarmMode === 'M') {
										_this.templateDatasClass[1].push({ key: response.data[i].templateCode, value: response.data[i].templateName });
									} else {
										_this.templateDatasClass[2].push({ key: response.data[i].templateCode, value: response.data[i].templateName });
									}
									//对象组模版
									_this.templateDatasClass[3].push({ key: response.data[i].templateCode, value: response.data[i].templateName });
								}
							}

						}
					});
				},

				/**
				 * 查询模版数据
				 */
				queryLoadDataObj: function (obj) {
					var _this = this;
					yufp.service.request({
						method: 'GET',
						url: "api/use/warnings/job/queryUseAlarmObject",
						data: obj,
						async: false,
						callback: function (code, message, response) {
							if (response.code != 0) {
								_this.$message(response.message);
							} else {
								var result = response.data;
								_this.exceptDatas = result.dateTypeObjList;
								_this.objDatas = result.useAlarmRuleList;

								// yufp.clone(_this.$refs.refBasicForm.formModel,result);
								yufp.clone(result, _this.$refs.refBasicForm.formModel);
								yufp.clone(result, _this.$refs.refWarnsForm.formModel);
								yufp.clone(result, _this.condDataModel);
								yufp.clone(result, _this.$refs.endRefForm.formModel);

								if (result.alarmClass === 'T') {
									_this.condDataModel.minValueT = result.minValue;
									_this.condDataModel.maxValueT = result.maxValue;
								} else if (result.alarmClass === 'L') {
									_this.condDataModel.minValueL = result.minValue;
									_this.condDataModel.maxValueL = result.maxValue;
								}

							}

						}
					});
				},


				filterFn: function () {
					return [];
				},
				changeAlermMode: function (val) {

					if (val === 'S') {
						this.currTemplateDatas = this.templateDatasClass[0];
					} else if (val === 'M') {
						this.currTemplateDatas = this.templateDatasClass[1];
					} else if (val === 'N') {
						this.currTemplateDatas = this.templateDatasClass[2];
					} else if (val === '+') {
						this.currTemplateDatas = this.templateDatasClass[3];
					} else {
						this.currTemplateDatas.splice(0);
					}


				},
				checkObjDataFn: function () {
					this.objectTabVisible = true;
				},
				userChoosefn: function () {
					this.objectUserTabVisible = true;
				},
				filterMethodFn: function (row, column, val) {
					var text = '';
					this.templateDatas.forEach(function (item) {
						if (item.key === val) {
							text = item.value;
							return true;
						}
					});
					return text;
				},
				/**
				 * 对象组配置
				 */
				checkGroupDataFn: function () {
					var _this = this;
					_this.groupTabVisible = true;
					var groupTargets = [];
					for (var i = 0; i < _this.objDatas.length; i++) {
						if (_this.objDatas[i].alarmMode === '+') {
							groupTargets.push(_this.objDatas[i].targetCode);
						}
					}
					_this.$nextTick(function () {
						_this.$refs.refGroupUsedTable.remoteData({ condition: { groupTargets: groupTargets } });
					})
				},
				setDisabled: function (row, column, cell, event) {
					if (row && row.alarmMode === "+" && column.property === "alarmMode") {
						var icon = cell.querySelector('.el-input__icon');
						cell.style.pointerEvents = 'none';
						if (icon) {
							icon.style.display = 'none';
						}
					}
				}
			},

		});
	};
});